Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I have always use .css files?

Tags:

html

css

Are .css files always needed? Or may I have a .css "basic" file and define other style items inside the HTML page?

Does padding, borders and so on always have to be defined in a .css file that is stored separately, or may I embed then into an HTML page?

like image 611
Layla Avatar asked Nov 28 '22 10:11

Layla


2 Answers

It is technically possible to use inline CSS formatting exclusively and have no external stylesheet. You can also embed the stylesheet within the HTML document. The best practice in web design is to separate out the CSS into a separate stylesheet. The reason for this is that the CSS stylesheet exists for the purpose of defining the presentation style of the document. The HTML file exists to define the structure and content of the document. And perhaps you may have JavaScript files which exist to add additional behavior to the document.

Keeping the presentation, markup, and behavior separate creates a cleaner design.

From a practical perspective, if you have a single external CSS stylesheet the browser can cache it. If multiple pages on your site have the same look and feel, they can use the same external stylesheet which only needs to be downloaded once by the web browser. This will make your network bandwidth bills lower as well as creating a faster end user experience.

like image 195
Michael Ridley Avatar answered Dec 09 '22 18:12

Michael Ridley


You can include CSS inside an HTML page. It goes within the <style> tag, which goes within the <head> tag:

<head>
  <style type="text/css">
    body{ background-color: blue; }
  </style>
</head>

Note, however, that it is best practice to use .css files.

like image 39
Michael Avatar answered Dec 09 '22 17:12

Michael