Is There a CSS Selector for Element Without Any Class

Can I write a CSS selector selecting elements NOT having a certain class or attribute?

Typically you add a class selector to the :not() pseudo-class like so:

:not(.printable) {
/* Styles */
}

:not([attribute]) {
/* Styles */
}

But if you need better browser support (IE8 and older don't support :not()), you're probably better off creating style rules for elements that do have the "printable" class. If even that isn't feasible despite what you say about your actual markup, you may have to work your markup around that limitation.

Keep in mind that, depending on the properties you're setting in this rule, some of them may either be inherited by descendants that are .printable, or otherwise affect them one way or another. For example, although display is not inherited, setting display: none on a :not(.printable) will prevent it and all of its descendants from displaying, since it removes the element and its subtree from layout completely. You can often get around this by using visibility: hidden instead which will allow visible descendants to show, but the hidden elements will still affect layout as they originally did. In short, just be careful.

Is there a CSS selector for element without any class?

With section:not([class]) you select every section without the class attribute. Unfortunately, it won't select those sections with an empty class attribute value. So in addition, we have to exclude these sections:

section:not([class]) { /* every section without class - but won't select Section C */
color: red;
}

section[class=""] { /* selects only Section C */
font-weight: bold;
}
<section>Section A</section>
<section class="special">Section B</section>
<section class="">Section C</section>

css selector for elements without a class

Assuming your HTML is properly formed, you can use :not() with the attribute selector []. Ex th:not([class])

Example:

th:not([class]) {  color: red;}
<table>  <tr>    <th style="position: relative; top: 0px;">      <div style="width: 48.003906px;" data-lngst="nullpx" data-ndx="2">123</div>    </th>    <th id="" class="abc_naem" nowrap="" style="position: relative; top: 0px;">      <div style="width: 44.003906px;" data-lngst="nullpx" data-ndx="4">123</div>      <th style="position: relative; top: 0px;">        <div style="width: 48.003906px;" data-lngst="nullpx" data-ndx="5">123</div>      </th>      <th id="" class="abc_phase" nowrap="" style="position: relative; top: 0px;">        <div style="width: 44.003906px;" data-lngst="nullpx" data-ndx="3">123</div>      </th>  </tr></table>

How can i style an element without adding a class or id to my HTML?

You can use last-child or last-of-type

ul li:last-child {
background-color: green;
}

ul li:last-of-type {
border: dotted red
}
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
<li>F</li>
</ul>

Select an element without selecting descendants

Use the CSS child combinator >:

.settings > ul > li > i {
opacity: 0.5;
}
<div class="settings">
<ul>
<li>
<i>Select this element</i>
<ul>
<li>
<i>but not this one</i>
<span></span>
</li>
<li>
<i>or not this one</i>
<span></span>
</li>
</ul>
</li>
</ul>
</div>

Target elements without *any* attributes?

A selector that matches a tag without attributes doesn't currently exist.

I read through the latest CSS selector reference and couldn't find a selector that does what you wish.

You can't use an asterisk in the attribute selector to select everything unfortunately. These two railroad diagrams represent what is allowed:

Railroad diagram of what text is allowed in the attribute selector

Railroad diagram of what string is allowed in the attribute selector

So your first two attempts are invalid, and the valid empty string seems to have no effect: