Skip to content

Is there a way to make certain additional CSS that is added only apply to specific pages? #2893

Answered by squidfunk
Fatih20 asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, you can use HTML in Markdown:

<link rel="stylesheet" href="link/to/stylesheet" />
<style>
  /* Inline styles */
</style>

Note that the stylesheet link probably has to be absolute, or it won't work correctly.

Alternatively, you can use theme extension, as Material for MkDocs does itself for the homepage, and provide a separate template for each site, which adds the relevant stylesheets.

<!-- Custom front matter -->
{% block extrahead %}
<!-- Extra stylesheets (can't be set in mkdocs.yml due to content hash) -->
<link
rel="stylesheet"
href="{{ 'overrides/assets/stylesheets/main.c…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Fatih20
Comment options

@squidfunk
Comment options

@Fatih20
Comment options

Answer selected by Fatih20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants