Is it a bad practice to use custom HTML attributes and style them with CSS?

后端 未结 4 1504
故里飘歌
故里飘歌 2021-01-27 15:24

Is there any problem creating a CSS class like this:

[test] { font: 13px; }

and use it in an HTML attribute as this:

&
4条回答
  •  甜味超标
    2021-01-27 16:18

    Your custom attributes are not valid HTML. You must use data-* attributes if you want to put custom data on your elements. This makes what you are doing bad practice.

    In addition, there are CSS classes already that should meet your needs, unless there is more to your question than you have described.

提交回复
热议问题