Style links without a class

CSS, Visual, Interactivity · Nov 23, 2022

When styling injected or generated HTML content, you might not have access to the classes or IDs of the elements you want to style. This can become especially annoying when dealing with link elements. Luckily, you can use the :not() selector with an appropriate attribute selector to check for the absence of a class and style links accordingly.

a[href]:not([class]) {
  color: #0077ff;
  text-decoration: underline;
}

As a bonus tip, you can use the previous tip about selecting any link to further enhance this solution.

More like this

  • CSS Interactivity

    A snippet collection of CSS3 code snippets and examples covering common user interactions.

    Collection · 15 snippets

  • Select any link with CSS

    You can use a CSS pseudo-class selector to style all links in a page, without worrying if they have been visited or not.

    CSS, Visual · Mar 6, 2022

  • Style links with no text

    Displays the link URL for links with no text.

    CSS, Visual · Nov 11, 2022

  • Image gallery with vertical scroll

    Creates a horizontally scrollable image gallery.

    CSS, Visual · May 5, 2022