Advanced Layout and Content Control
- CSS Counters: Use
counter-reseton a parent element andcounter-incrementon children to generate dynamic numbering without manual HTML updates. This is ideal for lists or sections that may change order. You can use thecontentproperty in a::beforepseudo-element to display the counter, and even addalttext to the content string to ensure the visual numbering is ignored by screen readers if it is purely decorative. - Multi-Column Layouts: The
column-widthproperty allows text to flow into columns automatically based on a minimum width (e.g.,15ch). By combining this withcolumn-count, you can set a maximum number of columns (e.g.,3 15ch), ensuring the layout remains responsive without becoming overly narrow or wide. Usebreak-inside: avoidon child elements like cards to prevent awkward content splits across columns.
Typography and Interaction Refinements
- User-Select: The
user-select: noneproperty 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-numsforces 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-thicknessto adjust the weight of the line,text-underline-offsetto control the distance from the text, andtext-decoration-style(e.g.,wavy,dotted) to change the appearance. These properties are animatable, making them excellent for interactive hover states on links.