CSS The Selectors Solution

Amy Howard
Amy Howard
Front End Web Development Techdegree Student 1,807 Points

Are single and double quotation marks used interchangeably in CSS?

In the solutions video for the CSS Selectors workshop the following code was given: at 1:39 input[type='submit'] at 1:54 input[type="text"]

Are the single and double quotation marks interchangeable?

Thanks!

4 Answers

Lukas Pscheidt
Lukas Pscheidt
2,229 Points

Hi Amy Howard

There is no difference between single or double quotes. You can simply use single quotes or double quotes, that is simply up to you, but my recommendation is to use double quotes. Especially when you will want to add some JS, you will find it very useful.

Here is example how I write code:

<a href="#" onclick="alert('Clicked');">Click me!</a>

EDIT: Thanks Steven Parker, I forgot to say, that quotes are interchangeable. But what i said, using single or double quotes is up to you.

So you can write code also:

<a href='#' onclick='alert("Clicked");'>Click me!</a>
Steven Parker
Steven Parker
149,203 Points

Quotes are also interchangeable in JS:

<a href='#' onclick='alert("Clicked");'>Click me!</a>
Steven Parker
Steven Parker
149,203 Points

The quote types are interchangeable, as long as they are used in matching pairs.

But it is a good practice to use one type consistently. Some style guides indicate a preference for one or the other, usually double quote (").

Google style guide recommends double quotes (") for HTML, and single(') for CSS. But then they're not totally consistent with that even in their own documentation. :wink:

Amy Howard
Amy Howard
Front End Web Development Techdegree Student 1,807 Points

Thanks to you both! Do either of you know how to access the "markdown cheatsheet" referenced at the bottom of this page? The link takes me to the main dashboard of the community, but I don't see it mentioned there...

Steven Parker
Steven Parker
149,203 Points

Clicking on the Markdown Cheatsheet below the "Add an Answer" area should not take you to another page, it should open a modal pop-up window. But here's a link to a page with even more information: Markdown Basics.

You may also want to watch this video on code formatting.