How to change the header size & colour of the LYT theme

Hey Folks

What I’m trying to do

I’m trying out the lyt theme & would like to change the header size & colour of the LYT theme with a css snippet

Things I have tried

I think i found the header size section in the lyt theme css file, so copied it into a header-size.css file and amended the top two values, saved/refreshed snippets, etc but that didnt seem work, so i added important but that also hasn’t worked.
(I noticed in other help suggestions it says em rather than rem after the font size, so i tried both. Not sure why its rem in the lyt theme)

body {
–h1: 1.125rem !important;
–h2: 1.1em !important;
–h3: 1.563rem;
–h4: 1.438rem;
–h5: 1.313rem;
–h6: 1.188rem;

--header-line-height: calc(0.8 * var(--line-height));

}

I havent gotten to the colour change yet, so if anyone can help with both / either that would be much appreciated.

Thanks
Marc

Found that this css from this post - Default theme - changing Headers size as a snippet - changes the colour of H2 - H6, but not H1, for some reason, and doesnt change the size of any of them.

  • << EDITOR and PREVIEW HEADERS >> */

.cm-header-1, .markdown-preview-view h1 {
font-size: 1.55em;
color: #797972;
font-weight: 400 !important;
}

.cm-header-2, .markdown-preview-view h2 {
font-size: 1.4em;
color: #797972;
font-weight: 400 !important;
}

.cm-header-3, .markdown-preview-view h3 {
font-size: 1.3em;
color: #797972;
font-weight: 400 !important;
}

.cm-header-4, .markdown-preview-view h4 {
font-size: 1.2em;
color: #797972;
font-weight: 400 !important;
}

.cm-header-5, .markdown-preview-view h5 {
font-size: 1.1em;
color: #797972;
font-weight: 400 !important;
}

.cm-header-6, .markdown-preview-view h6 {
font-size: 1em;
color: #797972;
font-weight: 400 !important;
}

Have you tried installing the Style settings plugin? I believe LYT supports being customized through that plugin, and it’ll be a whole lot easier than fiddling with the CSS files yourself.

1 Like

Yeah, normally I’d also recommend using Style Settings but the LYT theme doesn’t have many options.

With your above (just the colors):

.cm-header-1, .markdown-preview-view h1 {
color: var(--color-red);
}

.cm-header-2, .markdown-preview-view h2 {
color: var(--color-orange);
}

.cm-header-3, .markdown-preview-view h3 {
color: var(--color-yellow);
}

.cm-header-4, .markdown-preview-view h4 {
color: var(--color-green);
}

.cm-header-5, .markdown-preview-view h5 {
color: var(--color-blue);
}

.cm-header-6, .markdown-preview-view h6 {
color: var(--color-purple);
}

Add this to take care of the size:

body {
  --h1-size: 2.2em;
  --h2-size: 1.8em;
  --h3-size: 1.6em;
  --h4-size: 1.4em;
  --h5-size: 1.2em;
  --h6-size: 1.12em;
}

…and they set the inline-title color to inherit; probably the issue with the title not changing (the inline title is usually the same color as h1, but it’s inheriting the body text color in this case).

.inline-title { 
  color: var(--color-red);
}

And that should do it. :link: :brain:

The reason we can’t group everything together (as in your second post) is of how they decided to set up the theme. Tested in a bit older LYT vault, but should be fine.

3 Likes

I’ve checked inside the theme, you should be able to set the colors with these variables, in a snippet :

body {
  --h1-color: <whatyouwant> ;
  --h2-color: <whatyouwant> ;
  --h3-color: <whatyouwant> ;
  --h4-color: <whatyouwant> ;
  --h5-color: <whatyouwant> ;
  --h6-color: <whatyouwant> ;
}

That’s the beauty of variables and that’s why @kepano went to great lengths to implement them at the very base of the Obsidian CSS. You generally don’t have to bother with old fashioned CSS selectors.

2 Likes

I tried those first but they didn’t work for me.

It’s how they have the theme set, I think…

1 Like

Ah, OK. One of those cases where you have to resort to the !important directive. Like this:

body {
  --h1-color: red !important;
}

It’s always better to avoid !important, unless really necessary. Anyway, I just checked the above code, it works.

1 Like

Ahh thanks so much everyone! I did have the stylesettings plugin @holroy, switching from the minimal theme, but there’s no settings in there for lyt that i can see sadly.

Thats good to now about the variables in the base
@OlivierPS though im finding they dont work in this instance for me for some reason

I did get @ariehen colours to work (inc the h1) but the size is still not working. Here’s what i have in the snippet. Any newbie mistakes im making, or other things to try?

body {
–h1-size: 1.1em;
–h2-size: 1.1em;
–h3-size: 1.1em;
–h4-size: 1.4em;
–h5-size: 1.2em;
–h6-size: 1.12em;
}

.cm-header-1, .markdown-preview-view h1 {
color: var(–color-red);
}

.cm-header-2, .markdown-preview-view h2 {
color: var(–color-orange);
}

.cm-header-3, .markdown-preview-view h3 {
color: var(–color-yellow);
}

.cm-header-4, .markdown-preview-view h4 {
color: var(–color-green);
}

.cm-header-5, .markdown-preview-view h5 {
color: var(–color-blue);
}

.cm-header-6, .markdown-preview-view h6 {
color: var(–color-purple);
}

To make your forum posts here clearer, please start using four backticks surrounding any code or query examples. This will ensure that the text is not treated strangely by the forum software.

Alternatively you could specific for CSS, use ```css in front of the CSS, and ``` after it, to make it look nice, and to stop the forum software doing strange thing to your CSS code. (But using four backticks is a general tips to present any code, CSS or query examples within a forum post like these)

2 Likes

Thanks @holroy. I more meant newbie mistakes with my code for the header size not working, but thats really useful as im new to discord too, so will do :slight_smile:

I know, but I wanted to make a point of it, and I hadn’t installed the LYT theme myself, so I couldn’t answer the other part at that point in time. Now however, I’ve installed it, and found that the following seems to do the trick:

body.theme-light,
body.theme-dark {
  --h1-size: 40px;
  --h2-size: 36px;
  --h3-size: 32px;
  --h4-size: 28px;
  --h5-size: 24px;
  --h6-size: 20px;

  --h1-color: blue;
  --h2-color: yellow;
  --h3-color: green;
  --h4-color: red;
  --h5-color: purple;
  --h6-color: teal;
}

It all comes down to CSS specificity, and the LYT theme seems to define these color and size variables related to the body.theme-dark and body.theme-light selectors. This means that if you use just body in your selector, it has a lower specificity, and is therefore ignored.

Do note that in the above code, I’m setting the same color for both light and dark mode, which most likely isn’t a good idea. You should probably duplicate the code and set the colors accordingly to the light or dark mode.

I’m also using px to set the size, as using em is setting the size relative to whatever font size it relates to from before. I’m not well enough versed in CSS to figure that out at all times, so I tend to use px at least for test purposes to get the proper effect.

So feel free to change that back to using em’s or rem’s, as these selectors should override the LYT default selectors, and hopefully should give you reliable results with either size variant.

4 Likes

Amazing! Thanks @holroy :smiling_face: Works perfectly and learnt another thing. Much appreciated everyone

p.s can i also ask as part of this - what to add to change the header on mobile as that seems to be a seperate section, so assume i would need another block in the same css snippet for that?

-update- actually i see its reflected now sync has updated and seems to autosize accordingly (as far as i can tell) via the calc sections in the original css file.

Only thing i can’t work out is changing the link colour, (tried changing everything related to magenta, or links color in lyt stylesheet) but that’s another question so might one be for another post.

I’m sure you’ve already had a look at the dev tools a bit, but have a look here if you haven’t yet.

1 Like

Thanks @ariehen

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.