how to reference element by id within blazor component

Generate a guid string and use that:

<div class="preference">
    <label for="@elementId">Do you like cheese?</label>
    <input type="checkbox" name="@elementId" id="@elementId">
</div>

@code { 
    string elementId = Guid.NewGuid().ToString("N");
}