This question has been asked many times before.
The common answer is that it's sufficient to style with vertical-align: middle
.
Perhaps the problem is that none of these questions asked with a self-contained, complete example. SVG is a nice way to make the example self-contained, but the problem applies for any kind of image.
After this long prelude, why does applying vertical-align: middle
to both the radio group as well as to the SVG images not align them vertically to the middle?
<!DOCTYPE HTML>
<head>
<meta charset="UTF-8">
<style>
.myRadio .myradioG { vertical-align: middle; }
svg { stroke:black; stroke-width:5; opacity:0.5; }
</style>
</head>
<body>
<label class="myLabel">
<input type="radio" name="radioGroup" class="myradioG">
<svg width="100" height="100" viewBox="0 0 100 100">
<circle cx="50" cy="50" r="30"
style="fill:blue;" />
</svg>
</label>
<label class="inline-radio">
<input type="radio" name="radioGroup" class="myradioG">
<svg width="100" height="100" viewBox="0 0 100 100">
<rect x="20" y="20" rx="15" ry="15" width="60" height="60"
style="fill:red;" />
</svg>
</label>
</body>
Giving weight to the thousands of upvotes, this Q & A suggest likewise that replacing the style above with this one:
<style>
svg { stroke:black; stroke-width:5; opacity:0.5; vertical-align:middle; }
</style>
ought to work. It doesn't. Why?
Update
I see from Michael's answer one potential source of confusion. I omitted to specify what I'm trying to vertically align (because my hunch is that it's poor styling to use image icons that are not already quite uniform—same height, same resolution, same line thicknesses—as you see here from the identical svg width/height/viewBox).
I'd like to vertically align the radio buttons with the images.
Update 2
If someone could add a brief comment to clarify why the present solution works, that would be nice. The discussions say "set vertical-align: middle to whichever element you're trying to vertically align". Here we're trying to vertically align the radio buttons to the images, not the other way around, and yet a correct solution is to apply "vertical-align: middle" to the images, not the radio buttons. Why?