# Inline Google font code?

**URL:** <https://discourse.softpress.com/t/inline-google-font-code/23605>\
**Category:** Off Topic\
**Created:** [October 12, 2016, 12:25pm UTC](https://discourse.softpress.com/t/inline-google-font-code/23605 "2016-10-12T12:25:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![thatkeith](https://discourse.softpress.com/user_avatar/discourse.softpress.com/thatkeith/32/3795_2.png) [@thatkeith](https://discourse.softpress.com/u/thatkeith)\
**Post date:** [October 12, 2016, 12:25pm UTC](https://discourse.softpress.com/t/inline-google-font-code/23605/1 "2016-10-12T12:25:51Z")

</div>

I need help with a bit of custom code. I want to style some HTML text using a custom web font – anything from Google fonts would be cool, or I can host the fonts myself. The trouble is the formatting code _has_ to be inline… I can use

 (for example) but the src:url part doesn’t seem to work, and I really can’t use regular CSS.

This is in a CMS that doesn’t allow that level of customising. It’s a university-wide system; I simply cannot alter how it actually handles attempts at inserting CSS properly, although I have the admin’s blessing to try and find a way to do this. ☹

So… anyone have any ideas on custom web fonts through real inline code?

k

* * *

offtopic mailing list  
email@hidden  
Update your subscriptions at:

> **[Information for existing FreewayTalk / Groups.io users](https://discourse.softpress.com/t/information-for-existing-freewaytalk-groups-io-users/24891)**
>
> The purpose of this topic is to provide information about the migration from FreewayTalk and Groups io to Discourse and the differences in Discourse, as well as a place to discuss the good or bad of the migration. For those previously subscribing...

---

<div class="post-metadata">

**Author:** ![thatkeith](https://discourse.softpress.com/user_avatar/discourse.softpress.com/thatkeith/32/3795_2.png) [@thatkeith](https://discourse.softpress.com/u/thatkeith)\
**Post date:** [October 12, 2016, 12:35pm UTC](https://discourse.softpress.com/t/inline-google-font-code/23605/2 "2016-10-12T12:35:57Z")

</div>

FYI, here’s part of one experiment:

It only works if I have the right font locally installed; the src URL doesn’t work at all. I realise this may simply not be possible… but then again it just _might_!

k

* * *

offtopic mailing list  
email@hidden  
Update your subscriptions at:

> **[Information for existing FreewayTalk / Groups.io users](https://discourse.softpress.com/t/information-for-existing-freewaytalk-groups-io-users/24891)**
>
> The purpose of this topic is to provide information about the migration from FreewayTalk and Groups io to Discourse and the differences in Discourse, as well as a place to discuss the good or bad of the migration. For those previously subscribing...

---

<div class="post-metadata">

**Author:** ![Tim3](https://discourse.softpress.com/letter_avatar_proxy/v4/letter/t/f14d63/32.png) [@Tim3](https://discourse.softpress.com/u/Tim3)\
**Post date:** [October 12, 2016, 8:51pm UTC](https://discourse.softpress.com/t/inline-google-font-code/23605/3 "2016-10-12T20:51:16Z")

</div>

Hi Keith,  
There are three things that I thought you could try;

1. Try adding the stylesheet reference to the CMS just above your own HTML;

```auto
<link href="https://fonts.googleapis.com/css?family=Alfa+Slab+One” rel="stylesheet">
<div style=“font-family: 'Alfa Slab One'; etc.

```

I suspect you’ve tried this already!

1. Base64 encoding the font and loading it as a data URI in the style attribute;

```auto
<div style=“font-family: ‘Alfa Slab One’; src:url(‘data:application/x-font-woff;base64,d09GRgABAAAAAEwMAA0AAAAAjawA…..’ etc.

```

Sadly you can’t do this as is confirmed here;  
[http://stackoverflow.com/questions/8749225/loading-external-font-in-html-page-with-inline-css](http://stackoverflow.com/questions/8749225/loading-external-font-in-html-page-with-inline-css) [http://stackoverflow.com/questions/8749225/loading-external-font-in-html-page-with-inline-css](http://stackoverflow.com/questions/8749225/loading-external-font-in-html-page-with-inline-css)  
Inlining images works as does web fonts but not within an inline style. Damn!

1. If the CMS allows you to add scripts to the page then you can boot load the required Google Fonts CSS file while the page is downloading;

```auto
<script type="text/javascript">
	var d=document;
	var ls=d.createElement("link");
	ls.type="text/css",
	ls.rel="stylesheet",
	ls.href="https://fonts.googleapis.com/css?family=Alfa+Slab+One",
	d.getElementsByTagName("head")[0].appendChild(ls);
</script>
<div style="font-family: 'Alfa Slab One'; 
color: #000; font-size: 36px; padding: 10px; 
background-color: #f2612b;">
This is a test!
</div>

```

I’d be surprised if this works as most CMS editors will get upset if you try and insert script tags into the editor as it would be an easy way to inject code into the site.  
I seem to recall that eBay allowed scripts into their auction listings many years ago until they realised that they were being used to manipulate the displayed feedback score! 🙂

If you really must have this font in the CMS content then you could probably render your content with an inline SVG or even a regular graphic but then, as you know, this willonly ‘look like’ the intended design and will still be a graphic.  
Regards,  
Tim.

* * *

offtopic mailing list  
email@hidden  
Update your subscriptions at:

> **[Information for existing FreewayTalk / Groups.io users](https://discourse.softpress.com/t/information-for-existing-freewaytalk-groups-io-users/24891)**
>
> The purpose of this topic is to provide information about the migration from FreewayTalk and Groups io to Discourse and the differences in Discourse, as well as a place to discuss the good or bad of the migration. For those previously subscribing...

---

<div class="post-metadata">

**Author:** ![thatkeith](https://discourse.softpress.com/user_avatar/discourse.softpress.com/thatkeith/32/3795_2.png) [@thatkeith](https://discourse.softpress.com/u/thatkeith)\
**Post date:** [October 19, 2016, 10:58pm UTC](https://discourse.softpress.com/t/inline-google-font-code/23605/4 "2016-10-19T22:58:12Z")

</div>

Thanks Tim! I’ll check with the person who’s the official expert on the system we’re using here (Moodle).  
I already have graphics set up but I have to keep generating them, I’m hoping to be able to make this entirely self-contained so others can edit the text. 🙂

* * *

offtopic mailing list  
email@hidden  
Update your subscriptions at:

> **[Information for existing FreewayTalk / Groups.io users](https://discourse.softpress.com/t/information-for-existing-freewaytalk-groups-io-users/24891)**
>
> The purpose of this topic is to provide information about the migration from FreewayTalk and Groups io to Discourse and the differences in Discourse, as well as a place to discuss the good or bad of the migration. For those previously subscribing...

---

<div class="post-metadata">

**Author:** ![Tim3](https://discourse.softpress.com/letter_avatar_proxy/v4/letter/t/f14d63/32.png) [@Tim3](https://discourse.softpress.com/u/Tim3)\
**Post date:** [October 20, 2016, 10:24am UTC](https://discourse.softpress.com/t/inline-google-font-code/23605/5 "2016-10-20T10:24:59Z")

</div>

* * *

offtopic mailing list  
email@hidden  
Update your subscriptions at:

> **[Information for existing FreewayTalk / Groups.io users](https://discourse.softpress.com/t/information-for-existing-freewaytalk-groups-io-users/24891)**
>
> The purpose of this topic is to provide information about the migration from FreewayTalk and Groups io to Discourse and the differences in Discourse, as well as a place to discuss the good or bad of the migration. For those previously subscribing...
