0 votes
1 view
in Web Technology by (22.4k points)

Is it possible to select elements in CSS by their HTML5 data attributes (for example, data-role)?

1 Answer

0 votes
by (40.3k points)

If you want to use an attribute selector, then, do like this:

[data-role="page"] {

    /* Styles */

}

Note: There are many numbers of attribute selectors you can use for various scenarios that are all covered in the document I link to. Despite custom data attributes being a "new HTML5 feature". 

  • browsers will not have any problems with supporting non-standard attributes, so you should be able to filter them with attribute selectors; 
  • If you don't care about CSS validation either, as CSS doesn't bother about non-namespaced attribute names as long as they don't break the selector syntax.
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...