CSS: connect to web document

Learning CSS is the next after HTML and a required step to mastering web programming. This technology greatly expands the possibilities of marking pages on the Internet, and also reduces the time of the layout designer’s work on the project and reduces the amount of code. The theme is easy to understand, and the inclusion of CSS fonts does not cause difficulties for students.

Cascading Style Sheets

CSS (English Cascade Style Sheets - Cascading Style Sheets) is a markup language for web pages, on which Haakon Wyum Li began working in 1994.

css connection, hakon vium lee

In 1996, his work was recognized by the World Wide Web Consortium W3C, the first version of CSS1 was released. Since then, the language has undergone changes and adjustments in the direction of improvement and improvement.

Using CSS, connecting it to HTML code complements and extends the capabilities of the latter:

  • changing the text on the page as soon as the designer’s imagination can draw. At the same time, the functionality is wider than even among such mastodons among text editors like MS Word or LibreOffice;
  • allows you to apply formatting to large documents or a significant number of them within the same site, which causes webmasters to make less effort and time;
  • since the amount of code is reduced, the page loading speed increases, which is very important for users with a slow or limited connection;
  • has tools for cross-browser layout - a very important factor when increasing the types of devices with the ability to access the Internet (gadgets).

Currently used CSS4, working in tandem with HTML5, meets all the needs of modern website building. Many IT specialists believe that CSS4 has reached the top of its development and the next versions will not be released - they are not necessary.


CSS connection to HTML markup is done through a pair of <style> ... </ style> tag, inside which is placed an instruction for the behavior of an element on a web page, which has the following syntax:

p {text-indent: 5%;}

By applying this style to the <p> tag, paragraphs will be indented 5% from the beginning of the line throughout the entire document.

<style> p {text-indent: 5%;} </style>

The construct is called a style declaration and must necessarily be placed in the header part of a web document containing technical information between the <head> </ head> tags. The structure of this style declaration for the <p> tag is as follows:

  1. p - identifier.
  2. text-indent is a style property.
  3. 5% - property value.

These are special terms, definitions used in textbooks that are common among programmers. They should remember!

connecting external css files

Work with font

Information in the form of text is what 99% of visitors to the future site will come to in search of the necessary data. Therefore, readability of the font, its aesthetics and ease of visual perception play an important role for the attendance of the resource. The CSS connection here will be the action that is able to meet the listed requirements.

For font manipulation technology has a rich toolkit. The clearest in the form of a table is to provide another way to connect CSS fonts for the <p> tag, which aligns the text:

p align left text is pressed to the left (default)
center text is centered on the page
right text pressed to the right side
justify text fills lines on both sides (as in books)

An example of how the browser will display each style declaration:

connect css fonts

A number of styles are used to work with text. With their full list, purpose,their properties and values ​​can be found in the CSS reference.

External css files

CSS connection can be made through external files. In this case, besides the main HTML document, a document with styles is created separately and is located in the same directory as the HTML document itself. Their number can be any. The algorithm for connecting external CSS files consists of only two steps:

  1. In a text editor, create a document with styles, specify an extension for it..css.In this case, the <style> </ style> tags are not specified.
  2. In the HTML document in the header of the document (between the <head> </ head> tags), you need to reference this file with the following construct:<link href = "style.css" rel = "stylesheet">

Instead of style.css, you must specify your file address. In this case, the addressing can be both absolute and relative. The benefits are obvious:

  • external files can be applied to any number of web pages within the site;
  • if you specify absolute addressing, then to several sites. Obviously, with this, the markup is written once and there is no need to prescribe a style for each page;
  • when the programmer uses this method, the end user will not be able to view the CSS code.This way you can protect your creativity from plagiarism.

In addition, when working with markup code, the layout designer makes mistakes. They are easier to find and fix in a separate file that is small in size than in the usually cumbersome HTML code.

Using JavaScript technology

When formatting text on a web page, it is often necessary to set a style for a specific fragment that is different from the surrounding one. If this style is applied repeatedly on the website or in a large web document, then it is convenient to implement the connection of CSS through JavaScript through the construction:

<script> document.write("<link rel='stylesheet' href='style.css' type='text/css'>"); </script>

Again, instead of style.css, the relative or absolute address of the external file with the extension is written..css.

css connection via javascript

This method will be studied in more detail when studying programming in JavaScript. The mention of him here is a forced rush forward, but necessary for working with texts at this level.

Related news

CSS: connect to web document image, picture, imagery

CSS: connect to web document 27

CSS: connect to web document 89

CSS: connect to web document 53

CSS: connect to web document 40

CSS: connect to web document 3

CSS: connect to web document 88