MkDocs CSS Styles Documentation
This documentation describes the custom CSS styles available for MkDocs-rendered markdown files. These styles are loaded via the extra_css configuration in mkdocs.yml and provide enhanced formatting beyond standard markdown.
Available Stylesheets
The project uses four main custom CSS files:
common.css- Image modifiers, captions, tables, and Material for MkDocs customizationsiot.css- IoT-specific styles (breadboard images)db.css- Database course specific styles (floating text)slide.css- Full-screen slide/presentation modeopsman.css- Custom admonitions (currently only pied-piper style)
Image Styling with URL Fragments
MkDocs allows you to style images by adding fragment identifiers (hash anchors) to the image URL. This is the most convenient way to apply CSS styles without writing HTML.
Figure Images
For standard figures with controlled dimensions:
1 | |
Result: Image with max-width of 80% and max-height of 20rem.
Stretch Images
For full-width images like banners:
1 | |
Result: Image stretches to 100% width of container.
Centred Images
For centred block images with margins:
1 | |
Result: Centred image with max-width 500px and 4em vertical margins.
Centred Short Images
For smaller centred images:
1 | |
Result: Centred image with max-height 300px and 30px vertical margins.
Inline Centre Images
For small centred inline images:
1 | |
Result: Centred image with max-width 200px and 30px vertical margins.
For larger inline centred images, use #inline-center-large (max-width 400px).
Icon Images
For inline icons that align with text:
1 | |
Result: 24px height icon with vertical alignment at text-bottom.
With links:
1 | |
Icon Prefix
For icons that float to the left of a paragraph:
1 2 | |
Result: 24px icon floated left with 0.5em top margin.
Icon Indented
For indented icon links in lists:
1 | |
Result: 24px icon with 5em left margin, suitable for nested content.
Slide Icon
For icons positioned at the right of content:
1 | |
Result: 24px icon floated right, aligned with text-bottom.
Left Leader Images
For images that lead a paragraph, floating left:
1 2 3 | |
Result: 200px height image floated left with 30px right margin.
Right Inset Images
For smaller images inset on the right:
1 2 3 | |
Result: 160px height image floated right with 30px margins.
Breadboard Images (IoT-specific)
For circuit breadboard diagrams:
1 | |
Result: Centred block image with fixed width of 500px and 30px vertical margins.
Captions and Attributions
Image with Caption
Combine centred images with caption divs:
1 2 | |
Features: - Centred block display with max-width 500px - Italic, small font - Automatic spacing with -4em top margin and 4em bottom margin
Caption Without Space
For captions that don't need special margin adjustments:
1 | |
Source Attribution
To add source information that automatically prepends "Source: ":
1 2 | |
Result: Displays as "Source: Smith, J. (2023). Journal of Computer Science." in italic, small font.
Table Customizations
Suppressing Table Headers
To create a table without visible headers (useful for layout):
1 2 3 4 5 6 | |
Note: The horizontal rule (---) immediately before the table triggers header suppression.
Equal Column Widths
For tables with forced equal column widths:
1 2 3 4 5 6 | |
Result: Both columns forced to 50% width regardless of content.
Pretty Tables
For formatted tables with alternating row colors:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
Features: - Odd rows have light grey background (#f2f2f2) - Headers have blue background (#adf) with bold text - 5-10px cell padding
InfoTable (Legacy)
For tables with red branding:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Features: - Red border (3px top, 1px sides) - White text on red background headers - Centred on page
Floating Text (Database-specific)
For text that floats to the right of content:
1 2 3 | |
Custom Admonitions
Pied Piper Admonition (Operations Manual)
For special operations manual callouts:
1 2 3 4 | |
Result: Green-bordered admonition with custom Pied Piper icon.
Slide/Presentation Mode
The slide.css stylesheet enables full-screen presentation mode. This is typically triggered via JavaScript and creates an overlay for displaying content as slides.
Slide Elements
Content can be marked for slide display:
1 2 3 4 5 | |
Features: - Full viewport overlay (100vw × 100vh) - Centred content with large font size (2.5vw) - Fixed title at top - Fade-in animation - Click anywhere to dismiss
Slide Content Styling
When content is displayed in slide mode: - Images scale to max 90% width and 80vh height - Tables, lists, and blockquotes are left-aligned - Code blocks use large font (2.5vw) - Tables get alternating row colors - Headers have steelblue background
Material for MkDocs Adjustments
The common.css includes several adjustments for Material for MkDocs theme:
Link Colors
Links in paragraphs and lists use a blue color (#448aff).
Blockquote Margins
Blockquotes have 40px margins for better spacing.
Table Cell Alignment
Table cells are vertically aligned to top by default.
Font Size Inheritance
Tables, admonitions, and details elements inherit font size from parent instead of being forced to specific sizes.
Navigation Links
Navigation links allow superscript and subscript characters to display properly with left justification.
Material Symbols
Material Symbols Rounded icons are configured with: - FILL: 0 - Weight: 200 - GRAD: 0 - Size: 40
Index Page Utilities
Index Right Float
For floating content to the right on index pages:
1 2 3 | |
Result: Content floated right with 4em left margin and -10em right margin (extends into margin area).
Practical Examples
Example 1: Article with Images and Captions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Example 2: Reference Page with Tables
1 2 3 4 5 6 7 8 9 10 | |
Example 3: Documentation with Admonitions
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Example 4: Comparison Layout
1 2 3 4 5 6 7 8 9 | |
Configuration in mkdocs.yml
To use these stylesheets in your MkDocs project, add them to your mkdocs.yml:
1 2 3 4 5 6 | |
Required markdown extensions:
1 2 3 4 5 6 | |
Tips and Best Practices
- Use URL fragments for images - It's cleaner than writing HTML with class attributes
- Test responsive behavior - Some styles (like #left-leader) may not work well on mobile
- Combine styles carefully - Not all styles are meant to be combined
- Use semantic markup - Even with custom CSS, maintain proper HTML structure
- Check Material theme version - Some Material overrides may need adjustment for newer versions
- Optimize images first - CSS can size images, but start with appropriately-sized source files
- Consider accessibility - Ensure sufficient color contrast and provide alt text
- Preview before publishing - Run
mkdocs serveto preview how styles render
Browser Compatibility
These stylesheets use modern CSS features including: - CSS Grid and Flexbox - CSS Variables - Attribute selectors - Pseudo-elements
Tested and working in: - Chrome/Edge 90+ - Firefox 88+ - Safari 14+
Troubleshooting
Images not styling correctly
- Ensure the fragment identifier is spelled correctly (case-sensitive)
- Check that the CSS file is loaded in
mkdocs.yml - Verify the image path is correct
Tables not displaying as expected
- Make sure you have the
tablesmarkdown extension enabled - Check that the horizontal rule (
---) is on its own line for header suppression - Verify proper markdown table syntax
Slide mode not working
- Ensure
slide.jsis included inextra_javascript - Check browser console for JavaScript errors
- Verify the slide trigger elements are properly marked
Admonitions not displaying
- Confirm
admonitionmarkdown extension is enabled - Check that the admonition type is spelled correctly
- For custom admonitions like
pied-piper, ensureopsman.cssis loaded
Summary
The custom CSS stylesheets provide extensive formatting options for MkDocs markdown content:
- Image styling via URL fragments - Easy to apply without HTML
- Responsive layouts - Float, centre, and size images appropriately
- Table customizations - Suppress headers, force column widths, add styling
- Caption system - Professional figure captions and attributions
- Presentation mode - Full-screen slide display
- Material theme integration - Enhanced styles for Material for MkDocs
These styles enable rich, professional documentation while maintaining the simplicity of markdown writing.