Single versus double quotation marks in HTML & CSS [duplicate]
Asked Answered
C

3

16

Could anyone clarify the difference between single and double quotation marks in HTML5 & CSS.

Here's Google's contradictory use of single quotes in HTML:

<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>

And CSS:

font-family: 'Roboto', sans-serif;

While Bootstrap's documentation practices demonstrate the use of double quoted marks in HTML:

<link rel="stylesheet" href="https://cdn.rawgit.com/twbs/bootstrap/v4-dev/dist/css/bootstrap.css">

And CSS:

font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;

Which practice is the best and why ?

EDIT: Is there any valid reason why Google Fonts decided to use single quotes ?

Cedar answered 13/11, 2015 at 16:56 Comment(0)
G
31

Either are valid, but you probably should stick to a certain style guide. For example, Google's style guide suggest using double quotes for HTML and single quotes for CSS. (Although Google Fonts doesn't follow this exactly)

Gisele answered 13/11, 2015 at 17:6 Comment(2)
Exactly, I'm quite disturbed by Google's Fonts single quote usage.Cedar
@vorststoom, would you say you feel ...a disturbance in the fonts? Sorry, couldn't help myself :)Reformation
B
9

There's no best practice, because neither has any affect at all on how the code is parsed. You can deliminate attributes and other strings using ' or " interchangeably.

Barman answered 13/11, 2015 at 17:3 Comment(0)
F
3

Generally, no difference. They are interchangeable.

The only important note is not to use one inside itself.

For example in php:

echo '"hello world"';

Outputs - "hello world"

Or

echo "'hello world'";

Outputs 'hello world'

BUT

echo ""hello world"";

Will throw an error if the " is unescaped, as it's closing that parameter before the contents.

Fortitude answered 13/11, 2015 at 17:6 Comment(2)
Unrelated to the OP.Dryad
This is Relevant and Important.Densmore

© 2022 - 2024 — McMap. All rights reserved.