Pseudo-Element Icons
Use ::before or ::after with icon font character codes or SVG backgrounds to add icons to elements without extra HTML markup.
Use ::before or ::after with icon font character codes or SVG backgrounds to add icons to elements without extra HTML markup.
/* Icon font approach */
@font-face {
font-family: "Icons";
src: url("icons.woff2") format("woff2");
}
.icon-home::before {
font-family: "Icons";
content: "\e001";
margin-right: 0.5em;
}
/* CSS background SVG icon */
.external-link::after {
content: "";
display: inline-block;
width: 12px;
height: 12px;
background: url("data:image/svg+xml,...") center/contain no-repeat;
margin-left: 4px;
}
Decorative icons added via pseudo-elements are invisible to screen readers — this is correct behavior for purely decorative content.