Advanced Layout and Content Control

  • CSS Counters: Use counter-reset on a parent element and counter-increment on children to generate dynamic numbering without manual HTML updates. This is ideal for lists or sections that may change order. You can use the content property in a ::before pseudo-element to display the counter, and even add alt text to the content string to ensure the visual numbering is ignored by screen readers if it is purely decorative.
  • Multi-Column Layouts: The column-width property allows text to flow into columns automatically based on a minimum width (e.g., 15ch). By combining this with column-count, you can set a maximum number of columns (e.g., 3 15ch), ensuring the layout remains responsive without becoming overly narrow or wide. Use break-inside: avoid on child elements like cards to prevent awkward content splits across columns.

Typography and Interaction Refinements

  • User-Select: The user-select: none property prevents users from highlighting text. While historically used to prevent accidental selection during drag-and-drop, it is now most useful for UI elements like buttons where text selection is unnecessary and potentially distracting. Use this sparingly to avoid frustrating users who may want to copy text.
  • Tabular Numbers: When displaying numerical data in non-monospace fonts, font-variant-numeric: tabular-nums forces numbers to have uniform widths. This prevents layout shifting and improves readability in tables or dashboards where vertical alignment of digits is critical.
  • Text Decoration Styling: Modern CSS allows granular control over underlines beyond simple toggling. You can use text-decoration-thickness to adjust the weight of the line, text-underline-offset to control the distance from the text, and text-decoration-style (e.g., wavy, dotted) to change the appearance. These properties are animatable, making them excellent for interactive hover states on links.