Search code examples
htmlcssinline-styles

when to use "(quotes ) in inline styles


if i want to print out h1 in red the code will be

<h1 style = color:red > SECURITY  </h1>

so there is no double quotes around style and end with red but when we used

<img src="https://emojipedia/bacon_1f953.png" alt="bacon-img" "style=backgroud-color:blue;">

the code works and there was double quotes around style and if we added these quotes around first line the code wont work so when are quotes are added to HTML in general and when when its skipped


Solution

  • Not requiring quotes around attribute values is a relic from the olden ages when HTML was simpler, and it's there to remain interoperable with those old pages.

    In general, it's better to just always have the quotes there. If you ever need a space in an attribute value, you'll have to quote that, and then it'd be inconsistent to sometimes use quotes and sometimes not.