It seems strange to be mashing two languages together in a single document. Is this common practice?

Question

It seems strange to be mashing two languages together in a single document. Is this common practice?

Answer

On the web it is not unusual to see two languages mashed together in this way especially if we are looking at older sites. For example, some sites similarly couple the PHP and HTML languages.

While this type of tight coupling may not be all that uncommon, it is not a great habit to get into. As developers we should strive to “separate our concerns”. In the case of CSS, this means that we will usually want to keep our CSS out of our HTML document. In other words, it is best practice to use .css files rather than defining our styles inline or within the <style> tag. For a deeper dive into when inline styles might be advisable, take a look at this article.

In the next exercise you will learn how to create separate stylesheets!

23 Likes

The lesson says that if we define our styles within a tag for paragraph, it will effect all he paragraphs in the document. What if we want one of the paragraphs to be different? do we have to use inline style and manually change each on of the paragraphs?

12 Likes

If you want to style one paragraph only you must use an ID selector.

HTML

<p id="first">I am the first paragraph and I will be in red</p>
<p>I am the second paragraph</p>

CSS

#first {
  color: red
}

The ID is unique within a page is used to select one unique element.

36 Likes