0417 · 21.3Use stylesheets
Cambridge IGCSE Information and Communication Technology (0417) · Topic 21, Website authoring · 13:15
Practise this topic
Real past-paper questions on use stylesheets, with their mark schemes. Free with an account.
57 more Information and Communication Technology videos like this one
With a CIE Buddy account: every video in syllabus order, past-paper practice on each topic, and an AI tutor for anything unclear.
In this video
- 0:00CSS rules and selectors. Explains presentation layers, CSS and HTML roles, elements, selectors, properties, values and colour formats.
- 1:49Attached and inline styles. Compares shared attached stylesheets with inline formatting and shows how each applies CSS declarations.
- 2:56Creating external stylesheet rules. Builds a club-page stylesheet using element selectors, backgrounds, fonts, text formatting and comments.
- 5:05Formatting tables with CSS. Explains table selectors, padding, borders, dimensions, alignment and border-collapse settings for a timetable.
- 7:22Classes and relative file paths. Shows how to create reusable classes, link a stylesheet and use relative paths for portable website files.
- 9:47CSS cascade and practical checks. Explains style priority, reviews stylesheet benefits and gives practical exam checks for accurate CSS work.
Transcript: Use stylesheets
CSS rules and selectors
0:00One stylesheet can change the appearance of every heading across a school website. The words remain the same, but their colour, size and alignment change together. This separation makes a website easier to maintain. A carefully chosen rule can replace dozens of individual formatting changes. The presentation layer is used to display and format elements within a web page. Cascading Style Sheets, or C S S, is the language used to specify the presentation of web pages.
0:27Hypertext Markup Language, or H T M L, is used in the content layer to describe the content and structure of web pages. A browser combines these instructions to display the finished page. An element is a part of a web page identified by markup tags. Headings, paragraphs, list items and table cells are examples. The browser needs to know which elements each formatting rule affects. That connection between a rule and its target is the foundation of using stylesheets.
0:55A selector identifies the elements to which a formatting rule applies. A property is an aspect of appearance that can be changed. Its value specifies the required setting. Here, the paragraph selector applies navy text and a font size of eighteen pixels to paragraphs. The braces enclose the declarations belonging to that selector. Each declaration pairs a property with a value, separated by a colon. A semicolon finishes the declaration and separates it from the next one.
1:22In the code, the colour property is always spelt without the letter U, exactly as the board shows. Colours can be given as names, such as navy, or as hex codes. A hex code is a hash symbol followed by six characters, two each for the amounts of red, green and blue. The worked stylesheet below uses hex codes for a cream background and dark grey text. Type a hex code exactly as given, because one wrong character produces a different colour.
Attached and inline styles
1:49An attached stylesheet is a separate file of formatting rules that is linked to a web page. Several pages can use the same file. Changing a shared rule then updates matching elements across those pages. This gives consistent presentation and reduces repeated formatting instructions. An inline style is formatting written in the style attribute of one element’s opening tag. Its settings apply directly to that element. This is useful when a task requires one particular exception.
2:17For repeated formatting, an attached stylesheet provides a central place to make changes. The first inline style makes one paragraph maroon and bold. The style attribute contains declarations directly, because the opening tag already identifies the element. An external rule needs a selector because it sits separately from the content. Both methods use the same property names and values. The second line gives one heading a serif font at twenty-eight pixels.
2:43On the third line, a single table data cell gets a pale yellow background, with its text placed at the right and at the bottom. Inline styles can therefore set background, font and table properties, just as external rules do.
Creating external stylesheet rules
2:56Our worked task uses a supplied club page and a background image. We will create an external stylesheet, add reusable classes and attach the finished file. The content already contains headings, paragraphs, a list and a timetable. We can therefore concentrate on the presentation layer. Create a plain text stylesheet and save it as Club Style dot C S S. The file contains formatting rules, with no surrounding markup tags.
3:22Our generic external styles target element types directly. The h one, h two, h three, paragraph and list item selectors cover the required content. The body rule sets the page background and a shared font family. Background colour supplies a cream surface, while background image places the supplied paper image over it. The colour still shows wherever the image does not cover the background. Choose text colours that remain clear against both.
3:48Font family specifies the typeface used for text. Our rule requests the named font shown, followed by a generic sans serif fallback. If the requested font is unavailable, the browser chooses an available sans serif font. A fallback keeps the page usable on computers with different fonts installed. The text properties here cover font family, size, colour, alignment, bold and italic. Font size controls how large the characters appear. Text colour changes the characters themselves, while text alignment positions lines horizontally within their available space.
4:21Font weight controls boldness, and font style provides italic text. Our main heading has a font size of thirty-two pixels and is navy, centred and bold. The smaller headings create a visible hierarchy beneath it. Paragraphs and list items share an eighteen pixel size for consistent reading. Each declaration has a specific job, so you can adjust one feature without replacing the others. A comment is explanatory text in code that the browser ignores when applying formatting.
4:50The first line identifies the purpose of this stylesheet. Comments begin with a slash followed by an asterisk and finish with an asterisk followed by a slash. They help another person understand the rules during maintenance, and a practical task may ask you to attach one with exact wording.
Formatting tables with CSS
5:05A table is an arrangement of cells in rows and columns. Each cell is the space at the intersection of a row and a column. Table presentation can be controlled at several levels. These include the whole table, individual rows, header cells and ordinary data cells. The table selector controls the complete table, including its overall width and border model. A table row selector targets a horizontal group of cells.
5:29Header cells use the table header selector, while ordinary cells use the table data selector. Choose the level that matches the instruction in the task. Padding is the space between an element’s content and its border. Border spacing, in contrast, is the gap between the borders of neighbouring cells when the borders are kept separate. Padding gives the text room inside its cell. Spacing changes the distance between cells, so these settings affect different areas.
5:55This example gives cells ten pixels of internal padding and six pixels of separation. The border has three settings: thickness, line style and colour. Here, it is two pixels thick, solid and navy. Each cell keeps its own border because the table keeps its borders separate. Return to our worked file and add the table rules shown. The table width is eighty per cent of the page width. Each of our two columns takes half the table width.
6:21Percentage widths grow and shrink with the window, while pixel sizes stay fixed. The row height is set to forty-eight pixels, and a row grows taller only when its content needs more room. Horizontal alignment places text towards the left, centre or right of its cell. Vertical alignment positions cell content towards the top, middle or bottom. Our data cells use top alignment, while the header cells use middle alignment.
6:46The border collapse property decides whether neighbouring cell borders stay separate or merge into one shared line. The collapse setting gives our timetable a single grid of lines. Border spacing has an effect only when the borders are separate. Choose the setting first, because it determines how the boundaries between cells behave. For a borderless element, set the border to none, which removes the line and its thickness. A transparent border keeps its thickness while making the line invisible, so the layout does not shift.
7:14Both give an invisible boundary. When the task requires visible borders, give a line style such as solid as well as the thickness and colour.
Classes and relative file paths
7:22A style is a named set of formatting saved so it can be applied again. In a stylesheet, a style for an element, such as the p rule, applies to every element of that type on every linked page. A class, in contrast, is a named set of style rules that applies only to elements given that class name. One class can be used on any type of element. The paragraph rule affects every paragraph that matches it.
7:44A notice class applies only where the content includes that class name. Different element types can share the same class. A class is therefore useful for a repeated purpose, such as highlighting important information wherever it appears. A full stop before the name identifies a class selector in the stylesheet. The content’s class attribute contains the name without that full stop. Classes can contain the same properties as element rules.
8:08Backgrounds and font settings can therefore be reused alongside table sizes, alignment, spacing, padding and borders. Add these four class rules to the end of the worked stylesheet. The notice class highlights an announcement, while timetable targets the selected table. Session sets the selected row’s height and background. Entry colours its data cells because a cell’s own background appears over the row background. A relative file path gives the location of a file starting from the folder of the file that refers to it.
8:38Our page and stylesheet occupy the same folder. The link therefore needs only the stylesheet’s filename. The background image path is also relative, but its starting location is the stylesheet itself. Add the stylesheet link inside the page’s head section. Its relationship attribute identifies the resource as a stylesheet. The h ref attribute gives the relative path to the saved file. Apply the class names to the intended elements, then save the page and open it in a browser.
9:05An absolute file path, in contrast, gives the full location, starting from the drive of one computer. Relative file paths must be used for attached stylesheets because the absolute path points to a folder that exists only on the author’s computer. On a web server or the examiner’s computer, that stylesheet is not found, so the page appears unstyled. The relative link keeps working wherever the website folder is moved.
9:29Check the finished page against the task, property by property. The announcement should stand out, while the table should have visible shared borders and comfortable internal spacing. Confirm that all required text remains visible. Save the stylesheet in cascading stylesheet format with the dot C S S extension.
CSS cascade and practical checks
9:47The cascade is the order of priority that decides which style is applied when styles conflict. When two attached stylesheets set the same property for the same element, the later attached stylesheet overrides the earlier one. In this example, Extra dot C S S is attached second, so it changes the paragraph colour to maroon. The font size remains eighteen pixels because Extra dot C S S does not set it.
10:10An inline style overrides any attached stylesheet. Our paragraph therefore appears green, while it keeps the font size from the attached stylesheet. Within one stylesheet, a class rule takes priority over a plain element rule for the elements given that class. That is why our entry cells are pale blue, even though the table data rule sets white. An attached stylesheet stores its rules in a separate dot C S S file.
10:33An inline style, by comparison, is written inside the opening tag of one element. The rules of an attached stylesheet can affect every page linked to it. Each inline style affects only its own element, and it overrides the attached stylesheet when both set the same property. One attached stylesheet gives several pages consistent formatting. As a result, the whole website shares one house style and looks professional. A change to a shared rule updates every linked page at once.
11:00This reduces the time needed to maintain the website, because each page does not have to be edited separately. An absolute path points to a folder on the author’s own computer. When the website is uploaded to a web server, that folder does not exist there. The stylesheet is then not found, so the page loses its formatting. A relative path starts from the page’s own folder, so it still works after the whole site is moved.
11:24A style is applied to an element type, such as h one, and it formats every element of that type. A class is applied only to the elements given its name in their class attribute, and it can be used on different element types. In the stylesheet, the class name starts with a full stop. A typical Paper Three task asks you to create rules, save the stylesheet and attach it to supplied content.
11:46The internet is a worldwide network of interconnected computer networks, and the practical papers give no access to it, only source files. A screenshot is an image captured from all or part of a screen. Include requested screenshots in the Evidence Document, and put your name, centre number and candidate number on every printout. Marks are most often lost on small typing errors in the code, so copy hex codes, class names and comments with total accuracy.
12:12A property spelt with British spelling, a missing semicolon or a missing closing brace stops that rule from working. Other marks go on a class name without its full stop and a font family with no generic fallback. A stylesheet saved with the wrong extension loses marks too. An absolute path or links attached in the wrong order also lose marks, and answers naming a brand gain none. Work from the required properties, then check the browser result against each instruction.
12:37Confirm that the border setting, padding and alignment match the task. Capture requested evidence that clearly shows both the stylesheet code and the browser output. Finally, make sure your saved files produce the same result shown in your evidence. In short, the presentation layer is used to display and format elements within a web page. Shared external rules make consistent changes across matching content, while inline styles provide individual settings that override them.
13:03Classes select particular groups, and the later attached stylesheet overrides an earlier one. Keep paths relative, save the stylesheet correctly and check the finished page in a browser.