equivalent of stylable HTML elements?

I am working in a notebook. I would like to be able to easily style and restyle text fragments in a notebook text cell. I want to determine this styling in a style sheet, so that text fragments are styled separately from the other text. (So, I don't want to just select and style each fragment separately; I want stylesheet control over the styling of all code fragments at one go.) This is of course trivial in an HTML document: just place the fragment in a CODE element or a KBD and style it with CSS. How is it done in a Mma document?

Edit:

I'm going to reframe this a bit to emphasize work flow. Consider notebook usage and entering text in a text cell. In addition to being able to easily enter math, here are some types of text we might want (in terms of HTML elements): code, kbd, emph, samp, strong. If I understand correctly, Mma does not build in such text-level semantics to instead provides StyleBox as a rough equivalent of a span with a specified "style" playing the role of a class attribute for the span. So it appears the right way in Mma to discard the idea of semantic elements and focus on the idea that any semantics will be embodied in the names of styles. Unfortunately, if I press Alt-0 while entering text and then enter a style, it does not start a style box but instead styles the whole cell. (Is this desirable? It seems wrong.) So I think my question has become, can I hijack Alt-0 for starting style boxes with the same interface for entering a user-specified style?

(If this edit seems to shift the emphasis of the question too much, I can change it to a new question.)

• The question seems a bit general ... it would be easier to answer if it were about a concrete use case. Otherwise it sounds like you are asking for a tutorial on stylesheets ... A notebook is made of Cells, the second argument of which is a style name. I'd start here and follow the links at the end. – Szabolcs Sep 22 '17 at 18:11
• I wrote up something but I hit a roadblock. I put the partial post in a pastebin. Everyone should feel free to build on it (and post an aswer) if you can fix the remaining problem. pastebin.com/2Z2rBFnT – Szabolcs Sep 22 '17 at 18:50
• @Szabolcs Actually I would not mind a pointer to a decent stylesheet tutorial. But what you propose is quite close to what I am looking for. After reading what you wrote this seems possible enough, but I do not understand why some text might be formatted with other than the provided style (as you seem to indicate). Thanks! – Alan Sep 22 '17 at 21:29
• This looks helpful (I have not yet tried it): mathematica.stackexchange.com/questions/28286/… It seems one can define any style and then apply it with a keyboard shortcut. My ideal would be to invoke a request for the style name with a keyboard shortcut, which could then be entered in a dialog and applied. – Alan Sep 22 '17 at 21:39

• I'm hoping to use a simple StyleBox. Compare the use of Alt-8 (in the default style) to start entering code in a style box. I'd like to use Alt-0 to do something similar, with with my choice of style. – Alan Sep 23 '17 at 19:46
• @Szabolcs I don't know how to prevent a FormatType option from being added, but you can control what kind of FormatType is added by using CommonDefaultFormatTypes. For example, SetOptions[\$FrontEndSession, CommonDefaultFormatTypes -> {"TextInline" -> TextForm}] will make inline cells use TextForm as the FormatType. Nevermind, you already know that! So what is the issue with FormatType? – Carl Woll Sep 23 '17 at 20:26