<metaname="description" content="Learn how to use Cascading Style Sheets (CSS) to create your web application's user interface design on Full Stack Python.">
<linkrel="shortcut icon" href="/img/fsp-fav.png">
<title>Cascading Style Sheets - Full Stack Python</title>
<divstyle="padding: 0 0 20px 0; margin: 0 0 20px 0; background-color: #22B24C;">
<divclass="container">
<pclass="banner"><ahref="https://www.kickstarter.com/projects/mikeckennedy/python-for-entrepreneurs-video-course" style="color: #fff">Use Python to build your side business with the Python for Entrepreneurs video course!</a></p>
</div>
</div><ahref="https://github.com/mattmakai/fullstackpython.com"><imgstyle="position: absolute; top: 0; right: 0; border: 0;" src="/img/fork.png" alt="Fork me on GitHub"></a>
<p>Cascading Style Sheet (CSS) files contain rules for how to display and
lay out the HTML content when it is rendered by a web browser.</p>
<h2>Why is CSS necessary?</h2>
<p>CSS separates the content contained in HTML files from how the content
should be displayed. It is important to separate the content from the rules
for how it should be rendered primarily because it is easier to reuse those
rules across many pages. CSS files are also much easier to maintain on large
projects than styles embedded within the HTML files.</p>
<h2>How is CSS retrieved from a web server?</h2>
<p>The HTML file sent by the web server contains a reference to the CSS file(s)
needed to render the content. The web browser requests the CSS file after the
HTML file as shown below in a screenshot captured of the Chrome Web Developer
Tools network traffic.</p>
<p><imgsrc="/img/css-chrome-dev-tools.jpg" width="100%" alt="Google Chrome Web Developer Tools shows how CSS is separate from the HTML content." class="technical-diagram" /></p>
<p>That request for the fsp.css file is made because the HTML file for Full
Stack Python contains a reference to <code>theme/css/fsp.css</code> which is shown
in the view source screenshot below.</p>
<p><imgsrc="/img/fsp-css-source.jpg" width="100%" alt="View source screenshot for the fsp.css file in index.html." class="technical-diagram" /></p>
<h2>CSS preprocessors</h2>
<p>A CSS preprocessor compiles a processed language into plain CSS code. CSS
preprocessing languages add syntax such as variables, mixins and functions
to reduce code duplication. The additional syntax also makes it possible for
designers to use these basic programming constructs to write maintainable
front end code.</p>
<ul>
<li>
<p><ahref="http://sass-lang.com/">Sass</a> is currently the favored preprocessor in
the design community. Sass is considered the most powerful CSS preprocessor
in terms of advanced language features.</p>
</li>
<li>
<p><ahref="http://lesscss.org/">LESS</a> is right up there with Sass and has an ace up
its sleeve in that the <ahref="http://getbootstrap.com/">Bootstrap Framework</a> is
written in LESS which brings up its popularity.</p>
</li>
<li>
<p><ahref="http://learnboost.github.io/stylus/">Stylus</a> is often cited as the third
most popular CSS preprocessing language.</p>
</li>
</ul>
<h3>CSS preprocessor resources</h3>
<ul>
<li>
<p>The Advanced Guide to HTML and CSS book has a well-written chapter on
<ahref="http://www.deploypython.com/"><imgsrc="/img/sponsored/fsp-deployment-guide.png" alt="The Full Stack Python Guide to Deployments" width="100%"></a>
<pstyle="font-size: .8em; margin-top: 10px;">Searching for a complete, step-by-step deployment walkthrough? Learn more about <ahref="http://www.deploypython.com/">The Full Stack Python Guide to Deployments book</a>.