Add alternative text to CSS generated images

Before and after code examples showing alternative text added after a slash in the CSS content property

CSS generated images can have replacement text.

Most people use content to insert icons or decorative images. But what if that generated image carries information?

The content property accepts alternative text after a slash:

.element::before {
	content: url('/images/status.jpg') / 'Current status: available';
}

The value after the slash is the replacement text associated with the generated content.

This syntax is widely available in browsers, but assistive-technology behavior can still vary. For meaningful content, real HTML such as <img alt="…"> remains the safer choice.

Use CSS generated content for decoration or progressive enhancement, not for information that must always be announced.

You Don’t Need JavaScript ebook mockup

I wrote a guide about building modern UI with HTML and CSS first. It covers practical patterns you can use before reaching for JavaScript.

Learn more

    No strings attached, unsubscribe anytime!

    Other short articles you might like

    Explore more articles on front-end development, covering HTML, CSS and JavaScript for building high-performance websites.