Setting transparency for no data in raster in geoserver

I have a raster published in my geoserver with default raster style as below

<NamedLayer>
<Name>default_raster</Name>
<UserStyle>
<!-- Styles can have names, titles and abstracts -->
<Title>Default Raster</Title>
<Abstract>A sample style that draws a raster, good for displaying imagery</Abstract>
<!-- FeatureTypeStyles describe how to render different features -->
<!-- A FeatureTypeStyle for rendering rasters -->
<FeatureTypeStyle>
<Rule>
<Name>rule1</Name>
<Title>Opaque Raster</Title>
<Abstract>A raster with 100% opacity</Abstract>
<RasterSymbolizer>
<Opacity>1.0</Opacity>
</RasterSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>


And my imagery looks like

Which has black color set for no data. I want to make the no data to transparent. How that can be done?

I don't think it can be done with SLD. Publish your imagery as a image mosaic and change the "input transparent color" to black instead.

I'm not sure if this question is still relevant to anyone, but I found a solution using YSLD. Check out the documentation on the raster symbolizer and note the "intervals" color ramp. You can simply set the interval containing the no-data value to transparent. For example, if your no-data value is something north of 36000:

title: Discrete Ramp'
feature-styles:
- name: raster
rules:
- name: raster
- symbolizers:
- raster:
opacity: 1.0
color-map:
type: intervals
entries:
- ['#000000',0, 36000,'']


The format here is [<color>,<transparency>,<cell value>,<symbol>]. You can, of course, add more entries to symbolize other ranges of values. I hope this helps, even though it's a few years too late. :)