liveBook · Manning

CSS

As explained in Build a Website with ChatGPT

CSS is the stylesheet language used to specify the presentation and layout of documents, including web pages.

CSS controls how page objects look: their fonts, colors, sizes, spacing, and layout. HTML identifies objects such as headings and paragraphs; CSS supplies their styling. You can ask ChatGPT to write both, even if you do not know how to code. section 2.2.1 section 3.2.8

Read a small CSS rule

In `#displayPun { font-size: 24px; margin-top: 20px; }`, `#displayPun` points to the HTML element with that ID. Each declaration has a property, a colon, a value, and a semicolon. Change `24px` to another size to resize its text, keeping the `px` unit. section 2.2.1

To style a new page with ChatGPT:

  • Describe the HTML content, then request CSS separately. Specify colors, heading and body fonts, text sizes, and a maximum page width; 800px is a suggested starting point for a personal homepage. section 3.2.8
  • Save the HTML as `index.html` and the generated CSS as `styles.css` in the same folder. Check that the HTML contains `<link rel="stylesheet" type="text/css" href="styles.css">`; the filename must match the CSS file. section 3.2.8
  • For additional pages, request HTML that uses the same CSS file and adds no extra styles, particularly styles inside HTML tags. section 6.2
body {
  font-family: 'Roboto Serif', serif;      #1
  max-width: 800px;                        #2
  margin: auto;                            #3
}
 
header {
  background-color: dodgerblue;            #4
  padding: 20px;                           #5
  text-align: center;                      #6
}
 
header h1 {
  font-family: 'Josefin Sans', sans-serif; #7
  font-size: 48px;                         #8
  color: whitesmoke;                       #8
}
 
header h2 {
  font-family: 'Josefin Sans', sans-serif; #7
  font-size: 24px;                         #9
  color: whitesmoke;                       #9
  font-style: italic;    
}
 
main {
  font-size: 20px;                         #10
}
 
main h2 {
  font-family: 'Josefin Sans', sans-serif; #7
  font-size: 32px;                         #11
  color: dodgerblue;                       #11
}

A personal-homepage stylesheet shows how separate rules set body width, center the page, color the header, and style headings. section 3.3.2

Small edits can make a generated page your own: change a color keyword, adjust `max-width`, or change a `font-size` number while retaining its unit. For text that respects a visitor’s browser font-size setting, consider `rem` instead of `px`. If an element ignores its intended styling, compare its HTML class with the CSS selector: `class="entry-date"` needs `.entry-date`, not `.date`. section 3.4 section 5.3.2

How Build a Website with ChatGPT covers it

How deep it goes
Defines properties, declarations, and rules, then annotates generated stylesheets and offers edits rather than advanced CSS internals.
Examples
Shows a pun-display rule, a personal-homepage stylesheet, and a journal class-selector error.
What it assumes
Starts with no coding knowledge assumed and teaches the HTML and CSS basics needed to inspect generated code.
What you can do after
Apply it via ChatGPT to generate stylesheets, customize page appearance, and diagnose a mismatched class selector.
How it connects
Connects CSS to HTML elements, stylesheet links, class selectors, and JavaScript in browser-side pages.

Also explained in

Compare how 13 books explain CSS →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Website with ChatGPT. The section links point to the parts of the book it draws on.