Skip to content
Advertisement

Can javascript make a custom @rule of css?

CSS have rules like @media, @keyframes, etc. Can such be made using javascript, e.g. @myCustomRule. If yes then how ? If no then is there any alternative to that or just to go with CSS ?

Advertisement

Answer

While you can’t create your own custom @rules, you can use the CSSOM to create supported rules and insert them into one of the browser’s stylehseets with JavaScript:

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement