question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No way to change font with inline styles

See original GitHub issue

Browsers have the following default css:

code {
  font-family: monospace;
}

That means that currently there’s no way to change the font when using react-syntax-highlighter without a <style> element overriding that. If you add a fontFamily style to the <pre> element, it has no effect.

It seems like a good solution would be to add fontFamily: inherit to the <code> element, but that’d be a breaking change for some, probably.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

3reactions
conorhastingscommented, Sep 15, 2016

@bmathews ended up implementing this as codeTagProps - just to satisfy other potential use cases (adding a className to the element etc…)

https://github.com/conorhastings/react-syntax-highlighter/commit/a79352ad63239d6809630e23ff540a11df2950aa

so for your use case you could do something like

<SyntaxHighlighter 
  codeTagProps={{style: {fontFamily: 'inherit'} }}
/>
screen shot 2016-09-15 at 6 59 13 pm

Let me know if this works for you!

1reaction
bmathewscommented, Sep 15, 2016

That’s perfect! Thanks so much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML Font Size – How to Change Text Size Using Inline CSS ...
To change the size of your text with inline CSS, you have to do it with the style attribute. You type in the...
Read more >
No way to change font with inline styles · Issue #19 - GitHub
If you add a fontFamily style to the <pre> element, it has no effect. It seems like a good solution would be to...
Read more >
How to change text font in HTML? - Tutorialspoint
To change the text font in HTML, use the style attribute. The style attribute specifies an inline style for an element.
Read more >
Font Style does not change after adding style - Stack Overflow
The way you change a font in CSS is by doing this: ... This is called inline styling and it's generally frowned upon...
Read more >
How to Change Font in HTML - HubSpot Blog
To change font type purely with HTML, use the CSS font-family property. Set it to the value you want and place it inside...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found