Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monaco editor set font size

I am trying set the font size of the monaco editor by styling his surrounding div. That way is not working. So I have seen the monaco editor has an property font-size. So i tried it with this property. Unfortunately this also didn't work for me. The best way would be the way with CSS, because I am styling a few things simultaneously.

like image 260
Juhuy Avatar asked Feb 22 '18 17:02

Juhuy


2 Answers

There is an API for setting font-size, font-family, etc, Try not to Hack in the DOM since that probably won't be compatible in the future.

In your case, try this:

var editor = monaco.editor.create(document.getElementById("container"), {
    value: "// First line\nfunction hello() {\n\talert('Hello world!');\n}\n// Last line",
    language: "javascript",
    fontSize: "12px",
    lineNumbers: "off",
    roundedSelection: false,
    scrollBeyondLastLine: false,
    readOnly: false,
    theme: "vs-dark",
});

Checkout the Monaco Editor Playground for Basic Editor Options and start typing properties. It will autocomplete and you will see all available configuration properties with descriptions - or alternatively go to the api docs reference. good luck

like image 63
cancerbero Avatar answered Oct 27 '22 02:10

cancerbero


I'm not sure if it's possible to style the editor with CSS. However, you can use the fontSize property to change the editor's font size.

monaco.editor.create(document.getElementById("container"), {
    value: "function hello() {\n\talert('Hello world!');\n}",
    language: "javascript",
    fontSize: 20
});
like image 27
rcjsuen Avatar answered Oct 27 '22 03:10

rcjsuen