CSS Pseudo Element Decorations

Create decorative elements using CSS pseudo-elements with content and positioning for tooltips badges and icons.

CssConfig Management

Code

.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  background: #1a1a2e;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

CSS Pseudo Element Decorations

Create decorative elements using CSS pseudo-elements with content and positioning for tooltips badges and icons.

Code

.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  background: #1a1a2e;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

Explanation

::before and ::after inject decorative content (a tooltip arrow, a badge) without extra DOM nodes. Expected behavior: the generated box participates in layout like a real child element. Constraint: the content property must be set for the pseudo-element to render, and pseudo-elements are decorative only — they are not exposed to assistive technology.

Interactive Tools for This Topic