Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <p id="dest">この要素に指定されているフォント名を取得します。</p>
<hr>
<p><button type="button" onclick="check1()">チェック : getComputedStyle() 使用</button></p>
<p id="result1">判定結果</p>
<hr>
<p><button type="button" onclick="check2()">チェック 2 : canvas 要素でチェック</button></p>
<p id="result2">判定結果</p>
<hr>
<p>Author : <a href="http://neo.s21.xrea.com/">Neo</a></p>
              
            
!

CSS

              
                #dest {
  font-family: "デタラメゴシック", "游ゴシック";
}
              
            
!

JS

              
                // getComputedStyle() では style 属性値が拾えるだけ
// このサンプルの場合、「"デタラメゴシック", "游ゴシック"」という文字列が取れてしまい、
// 「デタラメゴシック」が効いているのか、「游ゴシック」が効いているのかは判断できない
function check1() {
  document.getElementById('result1').innerHTML = '判定結果 : ' + window.getComputedStyle(document.getElementById('dest')).fontFamily;
}

// canvas 要素に書き出してフォントをチェックするコードを利用
// font-family で「游ゴシック」と指定した時のフォントでレンダリングされていることが確認できる
function check2() {
  document.getElementById('result2').innerHTML = '判定結果 : ' + renderedfont(document.getElementById('dest'));
}

// https://stackoverflow.com/a/38910481
// どの指定が効いているかは分かる
function renderedfont(ele) {
    // スタイル未指定時のブラウザデフォルトフォントを拾っている
    var getDefaultFonts = function () {
        var iframe = document.createElement('iframe');
        var html = '<html><body>';
        var fonts;
        document.body.appendChild(iframe);
        iframe.contentWindow.document.open();
        iframe.contentWindow.document.write(html);
        var subele = iframe.contentWindow.document.createElement(ele.tagName);
        iframe.contentWindow.document.body.appendChild(subele);
        fonts = getComputedStyle(subele)['font-family'];
        document.body.removeChild(iframe);
        return fonts;
    }
    var fonts = getComputedStyle(ele)['font-family'] + ',' + getDefaultFonts();
    var fontsArray = fonts.split(',');
    var canvas = document.createElement('canvas');
    var ctx = canvas.getContext("2d");
    var testString = "abcdefghijklmnopqrstuvwxyz!@#$%^&*()ñ";
    var prevImageData;
    document.body.appendChild(canvas);
    canvas.width = 500;
    canvas.height = 300;
    fontsArray.unshift('"Font That Doesnt Exists ' + Math.random() + '"');

    for (var i = 0; i < fontsArray.length; i++) {
        var fontName = fontsArray[i].trim();
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        ctx.font = '16px ' + fontName + ', monospace';
        ctx.fillText(testString, 10, 100);
        var idata = ctx.getImageData(0, 0, canvas.width, canvas.height); 
        var data = idata.data
        if (prevImageData) {
            for (var j = 0; j < data.length; j += 3) {
                if (prevImageData[j + 3] !== data[j + 3]) {
                    document.body.removeChild(canvas);
                    return fontName;
                }
            }
        }
        prevImageData = data;
    }

    document.body.removeChild(canvas);
    return 'monospace';
}
              
            
!
999px

Console